﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XWG.JWBST.ProcessInterfaces;
using System.IO;
using System.Web;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace XWG.JWBST.ModifyPassProcess
{
    public class Process : IProcess
    {
        public string ProcessData(StreamReader reader, HttpContext context)
        {
            //读取提交数据并UrlDecode解码
            string receivemes = HttpUtility.UrlDecode(reader.ReadToEnd());

            //反序列化json对象
            JObject ob = (JObject)JsonConvert.DeserializeObject(receivemes);
            XWG.JWBST.JWBSTEntity.TbBstUser user = new JWBSTEntity.TbBstUser();
            user.PhoneNo = ob["phone"].ToString().Replace("\"", string.Empty);
            user.PassWord = ob["oldpass"].ToString().Replace("\"", string.Empty);
            string newpass = ob["newpass"].ToString().Replace("\"", string.Empty);
            user.UserId = JWBSTBLL.TbBstUserBLL.ISExist(user.PhoneNo, user.PassWord);
            if (!string.IsNullOrEmpty(user.UserId))
            {
               int num = XWG.JWBST.JWBSTBLL.TbBstUserBLL.ModefiyPass(newpass, user.UserId);
               if (num != 0)
               {
                   return "操作成功！";
               }
               else
               {
                   return "操作失败！";
               }
            }
            else
            {
                return "用户名或密码错误";
            }
        }
    }
}
